/**
 * Copyright 2010 Victor Egea Hernando
 *
 * RockScript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 * 
 * RockScript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with RockScript.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef ROCK_MACROS_H_
#define ROCK_MACROS_H_

// Useful macros for the parser
#define NEXT() { \
        lexer::freeTk(ctk_.tk_); \
        ctk_.tk_ = lexer_.next(); \
        ctk_.line_ = lexer_.line(); \
    }

#define MATCH(type) \
    if(ctk_.tk_.type_==type){ \
        NEXT(); \
    }else{ \
        unexpectedTkErr(); expectedTkErr(type); \
        throw std::logic_error("parser error"); \
    }

#define ERROR(errstr) {  \
        errorHnd_->parserError(ctk_.line_, errstr); \
        throw std::logic_error("parser error"); \
    }

#define ERROR_TK(type,errstr) { \
        std::stringstream ss; ss << "'" << lexer::tkt2str(type) << "'" << errstr ; \
        errorHnd_->parserError(ctk_.line_, ss.str().c_str());  \
    }

#define ERROR_MSG(errstr) { \
        errorHnd_->parserError(ctk_.line_, errstr); \
    }

#define UNEXPECTED() { \
        unexpectedTkErr(); \
        throw std::logic_error("parser error"); \
    }

#define POP_EXP() expp_--;
#define CLEAR_EXP() cregp_ = 1; expp_ = neregs_ = 1;
#define PUSH_EXP() { expp_++; if( expp_ > neregs_ ) neregs_++; }

#endif // ROCK_MACROS_H_
